package com.hdc.lw.word_server.controller;

import com.alibaba.fastjson.JSONObject;
import com.hdc.lw.word_server.po.Word;
import com.hdc.lw.word_server.service.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
public class WordController {

    @Autowired
    private WordService wordService;

    @RequestMapping("/insertWord")
    public String insertWord(HttpServletRequest request){
        Word word = new Word(null,request.getParameter("word"),request.getParameter("pronounce"),request.getParameter("description"),request.getParameter("speech"),false);
        String json = JSONObject.toJSONString(wordService.insertWord(word));
        return json;
    }

    @RequestMapping("/getWordList")
    public String getWordList(Integer uid,Integer size,Integer page){
        return JSONObject.toJSONString(wordService.getWordList(uid,size,page));
    }

    @RequestMapping("/getword")
    public String getWordByName(String name){
        return JSONObject.toJSONString(wordService.getWordByName(name));
    }

    @RequestMapping("/delWord")
    public String delWordById(Integer id){
        System.out.println(id);
        return JSONObject.toJSONString(wordService.delWordById(id));
    }

    @RequestMapping("/updateWord")
    public String updateWordByid(Integer id,String pronounce,String description){
        Word word = new Word(id,null,pronounce,description,null,false);
//        System.out.println(word);
        return JSONObject.toJSONString(wordService.updateWordByid(word));
    }

}
